import App from './App.vue'
import { routeGuard, checkAuth } from './utils/permission.js'
import store from './store'
// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'

// 添加全局路由守卫
uni.addInterceptor('navigateTo', {
  invoke: (args) => {
    console.log('Navigating to: ' + args.url);
    const authResult = checkAuth();
    return routeGuard({
      path: args.url
    }, {}, () => true);
  }
})

uni.addInterceptor('redirectTo', {
  invoke: (args) => {
    return routeGuard({
      path: args.url
    }, {}, () => true);
  }
})

uni.addInterceptor('reLaunch', {
  invoke: (args) => {
    return routeGuard({
      path: args.url
    }, {}, () => true);
  }
})

const app = new Vue({
	...App,
	store
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	
	// 添加全局路由守卫
	uni.addInterceptor('navigateTo', {
	  invoke: (args) => {
		console.log('VUE3 Navigating to: ' + args.url);
		const authResult = checkAuth();
		console.log('VUE3 Auth check result:', authResult);
		return routeGuard({
			path: args.url
		}, {}, () => true);
	  }
	})

	uni.addInterceptor('redirectTo', {
	  invoke: (args) => {
		console.log('VUE3 Redirecting to: ' + args.url);
		return routeGuard({
			path: args.url
		}, {}, () => true);
	  }
	})

	uni.addInterceptor('reLaunch', {
	  invoke: (args) => {
		console.log('VUE3 ReLaunching to: ' + args.url);
		return routeGuard({
			path: args.url
		}, {}, () => true);
	  }
	})

	return {
		app
	}
}
// #endif
